/**
 * Created by caoyang on 17/3/28.
 */

import React, {Component} from 'react';
import {
    StyleSheet,
    Text,
    View,
    NativeModules,
    InteractionManager,
    NativeEventEmitter,
} from 'react-native';

import NavigationBar from '../../common/NavigationBar';


const { RNToNative } = NativeModules;


const titleView = (
    <Text style={{fontSize:18, color:'white'}}>我要开票</Text>
);


const backToNativeEmitter = new NativeEventEmitter(RNToNative);
const subscription = backToNativeEmitter.addListener(
    'BackToNative',
    (reminder) => {
        console.log(reminder.name + '：收到通知');
    }, ''
);

export default class Invoicing extends Component {
    render() {
        return (
            <View style={styles.container}>
                <NavigationBar
                    titleView={titleView}
                    leftAction={this._popToNative}
                />
            </View>
        );
    }

    _popToNative = () => {
        InteractionManager.runAfterInteractions(()=> {
            // RNOpenOneVC这个也是写在原生里面的再PushNative中哦~
            RNToNative.RNToNativeVC('测试RNToNativeVC');
        });
    }

    componentDidMount() {
        const {navigator} = this.props;
        const routes = navigator.getCurrentRoutes();
        const currentRoute = routes[routes.length - 1];

        console.log(this.props.navigator.getCurrentRoutes());
    }

    componentWillUnMount() {
        subscription.remove();
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
    },
});
